
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections;
using System.Diagnostics;

using Swaf.Xml;
using Swaf;
using Swaf.Container;


namespace Swaf.Logging
{
	/// <summary>
	/// Summary description for EventLogLogObserver.
	/// </summary>
	public class EventLogLogObserver : BaseLogObserver
	{
		EventLogEntryType m_eventType = EventLogEntryType.Information;
		public EventLogLogObserver()
		{

		}
		public EventLogLogObserver(bool logCaller) : base(logCaller)
		{
		}
		public EventLogLogObserver(bool logCaller, string entryType) : base(logCaller)
		{
			init(entryType);
		}
		public EventLogLogObserver(string entryType)
		{
			init(entryType);
		}
		private void init(string entryType)
		{
			EventLogEntryType tmpType;
			try
			{
				tmpType = (EventLogEntryType) EventLogEntryType.Parse(typeof(EventLogEntryType), entryType,true);
			}
			catch(Exception e)
			{
				//ToDO:  Add some type of error reporting here.
				tmpType = EventLogEntryType.Information;
			}
			m_eventType = tmpType;
		}
		public void writeEntry(IDictionary info)
		{
			string message="";
			if (info["message"].GetType() == typeof(INameAddressSupport))
				message = ((INameAddressSupport) info["message"]).Xml;
			else
				message = info["message"].ToString();
			EventLog.WriteEntry(Application.currentApp.resMgr.getMacro("ApplicationId"), message, m_eventType);
		}
	}
}
